<template>
  <div id="type">
    <van-nav-bar title="吃了吗外卖" left-arrow @click-left="onClickLeft">
      <template #right>
        <router-link to="/login" tag="span">退出登录</router-link>
      </template>
    </van-nav-bar>

    <div class="shop_list_container">
      <header class="shop_header">
        <van-icon name="shop-o" />
        <span class="shop_header_title">附近商家</span>
      </header>
      <div class="shoplist_container">
        <ul v-for="(item, index) in shoplist" :key="index">
          <router-link :to="'/shop/' + item.id" tag="li" class="shop_li">
            <section>
              <img :src="uploads + item.image" class="shop_img" />
            </section>
            <hgroup class="shop_right">
              <header class="shop_detail_header">
                <van-tag type="warning">品牌</van-tag>
                <h4>{{ item.name }}</h4>
              </header>
              <h5 class="rating_order_num">
                <section class="rating_order_num_left">
                  <section class="rating_section">
                    <van-rate
                      :value="item.rating"
                      allow-half
                      :size="18"
                      color="#ffd21e"
                      void-icon="star"
                      void-color="#eee"
                    />
                    <span class="rating_num">{{ item.rating }}</span>
                  </section>
                  <section class="order_section">
                    月售{{ item.recent_order_num }}单
                  </section>
                </section>
                <section class="rating_order_num_right">
                  <span class="delivery_style delivery_left">吃了吗专送</span>
                  <span class="delivery_style delivery_right">准时达</span>
                </section>
              </h5>
              <h5 class="fee_distance">
                <p class="fee">
                  {{ item.minimum_order_amount }}元起送
                  <span class="segmentation">/</span>
                  配送费约{{ item.delivery_fee }}元
                </p>
                <p class="distance_time">
                  <span>距离{{ item.distance }}公里</span>
                  <span class="segmentation">/</span>
                  <span class="order_time">{{ item.order_lead_time }}分钟</span>
                </p>
              </h5>
            </hgroup>
          </router-link>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import axios from "axios";

export default {
  name: "type",
  data() {
    return {
      shoplist: [],
    };
  },
  methods: {
    onClickLeft() {
      this.$router.push("/");
    },
  },
  computed: {
    ...mapState({
      icons: (state) => state.badge.icons,
      titles: (state) => state.badge.titles,
      uploads: (state) => state.uploads,
    }),
  },
  created() {
    axios
      .get("/api/shop/shopType?type=" + this.$route.params.type)
      .then((response) => {
        this.shoplist = response.data.data;
      });
  },
};
</script>

<style lang="scss" scoped>
$bc: #e4e4e4;
$blue: #3190e8;
>>> .van-nav-bar {
  background: #42a5f3;
  color: #fff;
  .van-icon,
  .van-nav-bar__title {
    color: #fff;
  }
}
.shop_list_container {
  border-top: 1px solid $bc;
  background-color: #fff;
  .shop_header {
    margin-left: 10px;
    .shop_header_title {
      color: #999;
      font-size: 16px;
      line-height: 50px;
    }
  }
}
>>> .van-icon-shop-o {
  font-size: 20px;
}
h5 {
  margin: 0;
}
.shoplist_container {
  background-color: #fff;
}
.shop_li {
  display: flex;
  padding: 10px 10px;
  border-bottom: 1px solid #f1f1f1;
}
.shop_img {
  display: block;
  margin-right: 10px;
  width: 155px;
  height: 135px;
}
.shop_right {
  flex: auto;
  .shop_detail_header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    height: 50px;
    h4 {
      margin-left: 10px;
    }
  }
  .rating_order_num {
    display: flex;
    justify-content: space-between;
    height: 50px;
    .rating_order_num_left {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      .rating_section {
        display: flex;
        .rating_num {
          margin: 0 10px;
          font-size: 16px;
          color: #ff6000;
        }
      }
      .order_section {
        font-size: 12px;
        color: #666;
      }
    }
    .rating_order_num_right {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      .delivery_style {
        margin-left: 5px;
        padding: 2px;
        border-radius: 5px;
        border: 1px;
        font-size: 12px;
      }
      .delivery_left {
        border: 1px solid $blue;
        color: #fff;
        background-color: $blue;
      }
      .delivery_right {
        border: 1px solid $blue;
        color: $blue;
      }
    }
  }
  .fee_distance {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    color: #333;
    .fee {
      font-size: 14px;
      color: #666;
    }
    .distance_time {
      span {
        color: #999;
      }
      .order_time {
        color: $blue;
      }
      .segmentation {
        color: #ccc;
      }
    }
  }
}
</style>